package com.example.fund.util;

import com.example.fund.ApplicationUtil;
import com.example.fund.Constant;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DBManager
{
    private static SQLiteDatabase db;
    
    public static SQLiteDatabase getDB()
    {
    	if(db==null || !db.isOpen())
    	{
        	Context context = ApplicationUtil.getContext();
        	DatabaseHelper helper = new DatabaseHelper(context);
            db = helper.getWritableDatabase();
    	}
    	return db;
    }

    /**
     * close database
     */
    public static void closeDB()
    {
        Log.d(Constant.LOG_TAG, "DBManager --> closeDB");
        // 释放数据库资源
        if(db!=null && db.isOpen())
        {
        	db.close();
        }
    }

}